//
//  NSAttributedString+Extension.swift
//  WangFangWeiBo
//
//  Created by 王方 on 16/7/23.
//  Copyright © 2016年 wf. All rights reserved.
//

import UIKit

extension NSAttributedString {
    //根据表情模型生成富文本
    class func attributedStringWithEmoticon(emoticon:WFEmoticon,font:UIFont)->NSAttributedString{
        //1.通过表情按钮生成表情图片
        let image = UIImage(named: emoticon.path!)
        //2.通过UIImage创建一个文本附件(textattachment)
        let attachment = WFTextAttachment()
        attachment.image = image
        attachment.emoticon = emoticon
        attachment.bounds = CGRect(x: 0, y: -4, width: font.lineHeight, height: font.lineHeight)
        //3.通过attachment创建富文本
        let attributeStr = NSAttributedString(attachment: attachment)
        
        return attributeStr
    }


}
